﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>个人资料</title>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/ydui.css?v=1.1.4" rel="stylesheet" />
    <script src="../js/ydui.flexible.js"></script>
    <link rel="stylesheet" type="text/css" href="../css/all.css?v=20180302" />
    <style type="text/css">
        /*.cell-select {
            display: block;
            color: #2A2A2A;
            padding-left: 4rem;
            align-items: center;
        }*/

        .m-cell .cell-left{width:80px;}
        .cell-fileinput {
            position: absolute;
            width: 100%;
            z-index: 9999999;
            width: 70%;
            height: 1rem;
            right: 0;
            opacity: 0;
        }
        .m-cell:after{border:none;}
    </style>
</head>

	<body ms-controller="userview" class="ms-controller">
		<div class="page-group">		
			<div class="page page-current" id="rounter">
				<div class="g-flexview">
			        <header class="m-navbar">
			            <a onclick="history.back()" class="navbar-item"><i class="back-ico"></i></a>
			            <div class="navbar-center"><span class="navbar-title">个人资料</span></div>
			        </header>			
					<div class="g-scrollview">
						<input type="file" class="cell-fileinput" onchange="upload(this)" accept="image/jpeg,image/jpg,image/png"/>
						<div class="m-cell">
				            <div class="cell-item">
				                <div class="cell-left">我的头像</div>
				                <div class="cell-right cell-arrow cell-file" style="min-height:2rem;">
				                	<img ms-attr="{src:@UserImg}" class="person-img" style="width:1.2rem;height:1.2rem;"/>
				                </div>
				            </div>
                            <div class="cell-item">
                                <div class="cell-left">昵称</div>
                                <div class="cell-right"><input type="text" class="cell-input" placeholder="请输入昵称" ms-duplex="@ModelData.NickName" /></div>
                            </div>
                            <div class="cell-item">
                                <div class="cell-left">手机号</div>
                                <div class="cell-right"><input type="number" class="cell-input" placeholder="请输入手机号" ms-duplex="@ModelData.Telephone" oninput="if(value.length>11)value=value.slice(0,11)"/></div>
                            </div>
				                    
				        </div>
                        <a class="btn  btn-primary" style="width:95%;margin:0.2rem;position:fixed;bottom:0" ms-on-tap="@Save()">
                            保存
                        </a>
					</div>
				</div>
			</div>
						
		</div>


        <script src="https://cdn.bootcss.com/jquery/2.2.0/jquery.min.js"></script>
        <script src="../js/ydui.js"></script>
        <script src="../js/avalon.mobile.min.js"></script>
        <script src="../js/ComFunJS.js?v=20180331"></script>
        <script src="../js/lrz/lrz.all.bundle.js"></script>
        <script>

        var model = avalon.define({
            $id: "userview",
            ModelData: { "Telephone": "", "NickName": "", "UserImg": "" },
            UserImg: "",
            GetModelData: function () {
                $.getJSON("/api/user/userinfo", function (r) {
                    if (r.error == "") {
                        model.ModelData = r.result;
                        if (model.ModelData.UserImg) {
                            if (model.ModelData.UserImg.indexOf("http") == 0) {
                                model.UserImg = model.ModelData.UserImg;
                            } else {
                                model.UserImg = ComFunJS.FilePath(model.ModelData.UserImg, "120/120");
                            }
                        } else {
                            model.UserImg = "../img/backgo.jpg";
                        }
                    }
                })

            },
            Save: function () {
               
                $.post("/api/user/updateuserinfo", model.ModelData.$model, function (r) {
                    if (r.error == "") {
                        YDUI.dialog.toast("保存成功", 'none', 2000, function () {
                            history.back();
                        });
                    } else {
                        YDUI.dialog.toast(r.error, 'none', 2000);
                    }

                })

            },
            

        });
        avalon.ready(function () {
            if (ComFunJS.isLogin(true)) {
                model.GetModelData();
            }
        })

        function upload(file) {
            ComFunJS.fileUpload(file, function (imgs) {
                model.ModelData.UserImg = imgs[0].ID;
                model.UserImg = ComFunJS.FilePath(model.ModelData.UserImg, "120/120");
            })
        }

        </script>

	</body>
	
</html>
